/*
 * v1.1 by tonydon site:txdnet.cn
 * netbeansIDE 7.1
 */
package cn.txdnet.txcms.service;

import cn.txdnet.txcms.dao.CatalogsDAO;
import cn.txdnet.txcms.domain.Catalogs;
import cn.txdnet.txweb.basedao.FacadeProxy;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author txdnet
 */
public class CatalogsService {

    public static boolean makeCatalogs(Catalogs ct) {
        return FacadeProxy.getManualCommitProxy(CatalogsDAO.class).insertCatalogs(ct);
    }

    // 更新基本信息
    public static boolean updateIsOpen(byte isopen, int cid) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("isopen", isopen);
        m.put("cid", cid);
        CatalogsDAO dao = FacadeProxy.getManualCommitProxy(CatalogsDAO.class);
        return ( dao.updateBase(m)>0?true:false );
    }

    public static boolean updateCname(String cname, int cid) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("cname", cname);
        m.put("cid", cid);
        CatalogsDAO dao = FacadeProxy.getManualCommitProxy(CatalogsDAO.class);
        return ( dao.updateBase(m)>0?true:false );
    }

    public static boolean updateOrdnum(int ordnum, int cid) {
        Map<String, Object> m = new HashMap<String, Object>(2);
        m.put("ordnum", ordnum);
        m.put("cid", cid);
        CatalogsDAO dao = FacadeProxy.getManualCommitProxy(CatalogsDAO.class);
        return ( dao.updateBase(m)>0?true:false );
    }

    // 删除终分类
    public static boolean deleteFinal(int cid, int rid) {
        return FacadeProxy.getManualCommitProxy(CatalogsDAO.class).deleteFinal(cid, rid);
    }

    // 查询分类列表
    public static List<Map> listByFactor(Map m) {
       return FacadeProxy.getAutoCommitProxy(CatalogsDAO.class).listByFactor(m);
    }

    // 通过路径查询相关分类列表
    public static List<Catalogs> listByCtp(String ctp) {
        return FacadeProxy.getAutoCommitProxy(CatalogsDAO.class).listByCtp(ctp);
    }

    /**
     * 得到当前类目总记录数
     * @return 
     */
    public static int getCatalogsNum() {
        return FacadeProxy.getAutoCommitProxy(CatalogsDAO.class).getCatalogsNum();
    }
    
    /**
     * 查询catalogs
     * @param cid
     * @return 
     */
    public static Catalogs getCatalogsByCid(Integer cid){
        return FacadeProxy.getAutoCommitProxy(CatalogsDAO.class).queryCatalogsByCid(cid);
    }
}